#include <stdio.h>

#include <iostream>
#include <map>
#include <vector>

using namespace std;
class Solution {
public:
    vector<int> twoSum(vector<int> &nums, int target) {
        vector<int> ans;
        map<int, int> hash;
        for (size_t i = 0; i < nums.size(); i++) {
            auto find_target = target - nums[i];
            auto find        = hash.find(find_target);
            if (find == hash.end())
                hash.insert(pair<int, int>(nums[i], static_cast<int>(i)));
            else {
                ans.push_back(find->second);
                ans.push_back(i);
                break;
            }
        }
        return ans;
    }
};
int main(void) {
    printf("两数之和c++\n");

    vector<int> nums = {1, 2, 5, 7, 3};
    auto buf         = Solution().twoSum(nums, 12);
    if (!buf.empty())
        printf("ans: %d, %d\n\n", buf[0], buf[1]);
    else
        printf("ans: None\n\n");
    return 0;
}